<?php
session_start();
if (isset($_SESSION['GoogleToken']) && $_SESSION['GoogleToken'])
{
	$SHARED_SECRET_KEY = "76r7r";
	$userData = array("string" => md5($_SESSION['GoogleToken']));
	// Now comes the important part. 
	// We will hash the array contents and the secret key 
	// concatenated together with a pipe character.
	// Expiration is one day
	$expire = time() + 24 * 3600;
	$hash = md5(implode('|', $userData).'|'.$expire.'|'.$SHARED_SECRET_KEY);
	// Finally, we add the hash to the array of parameters
	$userData["hash"] = $hash;
	$userData["hashExpire"] = $expire;

	// We need to organize the array in the proper structure to ensure hashing order, and encode the output into JSON format
	$jsonArray = array();
	foreach ($userData as $key => $value) {
		$jsonArray[] = array($key => $value);
	}

	$json = json_encode($jsonArray);
	header("Location: http://www.ustream.tv/embed/hashlock/pass?hash=" . $json);

}
else
{
	require('hash.error.html');
}
?>